package com.zhongcw.test.spring.boot.thymeleaf.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ZCW
 * @createTime 2018/4/4
 * @lastUpdateTime 2018/4/4 ZCW
 */
@Controller
public class Index {

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("/**")
    public void index(HttpServletRequest request, HttpServletResponse response) {

        String remotePath = String.format("http://192.168.0.178:8080%s", request.getRequestURI().toString());

//        restTemplate.getForObject(remotePath, String.class, request, response);
        restTemplate.postForObject(remotePath,request,String.class);
    }

    @PostMapping("/index/123")
    public void index1(HttpServletRequest request, HttpServletResponse response) {

        String remotePath = String.format("192.168.0.178:8080{}", request.getRequestURI().toString());

        restTemplate.getForObject(remotePath, String.class, request, response);
    }
}
